package cn.com.suiyi.shixingshengxian.firstrun;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;

import butterknife.InjectView;
import cn.com.suiyi.shixingshengxian.R;
import cn.com.suiyi.shixingshengxian.base.BaseActivity;
import cn.com.suiyi.shixingshengxian.firstrun.adapter.FirstRunPagerAdapter;
import cn.com.suiyi.shixingshengxian.main.MainActivity;

public class FirstRunActivity extends BaseActivity {
    @InjectView(R.id.viewpager_firstrun)
    ViewPager viewpagerFirstrun;
    @InjectView(R.id.button_firstrun)
    Button buttonFirstrun;
    private int imgs[] = {R.mipmap.w01, R.mipmap.w02, R.mipmap.w03};
    private FirstRunPagerAdapter adapter;
    private int currentPaper;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewpagerFirstrun.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                currentPaper = position;
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        buttonFirstrun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (currentPaper == imgs.length - 1) {
                    Intent intent=new Intent(FirstRunActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                }
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    public int getLayout() {
        return R.layout.activity_firstrun;
    }


    @Override
    public void initView() {
        adapter = new FirstRunPagerAdapter(imgs, this);
        viewpagerFirstrun.setAdapter(adapter);

    }

}
